<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box {
            border:1px solid #ccc;
            position: absolute;
            left:0;
            right:0;
            margin:20px auto;
        }
    </style>
</head>
<body>
    <canvas id="box" width="800" height="450"></canvas>
</body>
<script>
    //获取canvas
    const boxDom=document.querySelector('#box')
    //生成canvas对象 相当于echarts中的echarts.init(boxDom)
    const context=boxDom.getContext('2d')

    //canvas属性,填充样式
    context.fillStyle='#ff0';
    //边框样式
     context.strokeStyle='#f00';
     //边框宽度
     context.lineWidth=2;

    //绘制填充矩形
    context.fillRect(20,40,200,80);

   //绘制描边矩形
   context.strokeRect(20,40,200,80);

   //擦除矩形
   context.clearRect(19,39, 150,50);
   
    
</script>
</html>